/************************************************
* 文件描述: 自助服务页面
* 待完善:
* 待优化:
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*************************************************/
#include "diysupport_page.h"
#include "globaldata.h"
#include <QDebug>
/************************************************
* 函数名称：DIYSupportPage
* 功能描述：构造函数
* 输入参数：窗口各参数类
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
const QString BTN_TO_LABEL_STYLE = "QPushButton{border:0px;border-radius:4px;background:transparent;}"
                                   "QPushButton:Hover{border:0px;border-radius:4px;background:transparent;}"
                                   "QPushButton:Pressed{border:0px;border-radius:4px;background:transparent;}";
DIYSupportPage::DIYSupportPage(QWidget *parent)
    :QWidget(parent)
{
    this->setWindowTitle("diysupport_page");

    initPageLocation();
    // 响应用户手册
    m_daemonIpcDbus = new DaemonIpcDbus();
}
/************************************************
* 函数名称：changePageForTheme
* 功能描述：构造函数
* 输入参数：界面参数类
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void DIYSupportPage::changePageForTheme(const QString& str)
{

    if("ukui-dark" == str || "ukui-black" == str)
    {
        m_pKylinPic->setStyleSheet("border-image:url(:/data/banner.png);border:0px;");

        m_pKylinOfficialWeb_2->setStyleSheet("background-color:transparent;color:rgba(249, 249, 249, 1);");
        m_pKylinOfficialWeb_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pKylinManual_2->setStyleSheet("background-color:transparent;color:rgba(249, 249, 249, 1);");
        m_pKylinManual_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

    }
    else
    {
        m_pKylinPic->setStyleSheet("border-image:url(:/data/banner.png);border:0px;");

        m_pKylinOfficialWeb_2->setStyleSheet("background-color:transparent;color:rgba(48, 49, 51, 1);");
        m_pKylinOfficialWeb_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pKylinManual_2->setStyleSheet("background-color:transparent;color:rgba(48, 49, 51, 1);");
        m_pKylinManual_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

    }
}
/************************************************
* 函数名称：initPageLocation
* 功能描述：窗口页面布局
* 输入参数：
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void DIYSupportPage::initPageLocation()
{
    m_pKylinPic = new QLabel(this);
    m_pKylinPic->setFixedSize(700,331);

    QPalette peMid;
    QColor colorMid = palette().color(QPalette::Mid);
    qDebug() << QString("rgba:%1,%2,%3").arg(colorMid.red()).arg(colorMid.green()).arg(colorMid.blue());
    peMid.setColor(QPalette::Text,colorMid);

    m_pMoreInfoLink_1 = new QLabel(this);
    m_pMoreInfoLink_1->adjustSize();//setFixedSize(368,17);
    m_pMoreInfoLink_1->setText(tr("Click "));
    m_pMoreInfoLink_1->setPalette(peMid);

//    m_pMoreInfoLink->setText(tr("点击<style> a {text-decoration: none} </style> <a href=\"http://www.kylinos.cn\">了解更多服务与支持内容</a>，跳转至KylinOS官方网站技术支持页面"));
    m_pMoreInfoLink_2 = new QLabel(this);
    m_pMoreInfoLink_2->adjustSize();
    m_pMoreInfoLink_2->setCursor(QCursor(Qt::PointingHandCursor));
    m_pMoreInfoLink_2->setText(tr("to know more about support"));
    m_pMoreInfoLink_2->installEventFilter(this);

    QPalette peHighlight;
    QColor colorHighlight = palette().color(QPalette::Highlight);
    qDebug() << QString("rgba:%1,%2,%3").arg(colorHighlight.red()).arg(colorHighlight.green()).arg(colorHighlight.blue());
    peHighlight.setColor(QPalette::Text,colorHighlight);

    m_pMoreInfoLink_2->setPalette(peHighlight);

    m_pMoreInfoLink_3 = new QLabel(this);
    m_pMoreInfoLink_3->adjustSize();
    m_pMoreInfoLink_3->setText(tr("，to KylinOS Official Web"));
    m_pMoreInfoLink_3->setPalette(peMid);

    m_pPageTitle = new QLabel(this);
    m_pPageTitle->adjustSize();//->setFixedSize(168,17);
    m_pPageTitle->setText(tr("Users can solve problems through the ways below."));//用户还可通过以下方式解决问题");
    m_pPageTitle->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
    m_pPageTitle->setPalette(peMid);

    m_officialWeb = new MyClickWidget(this);
    m_officialWeb->setFixedSize(340,120);
    m_officialWeb->setObjectName("officialWeb");


    connect(m_officialWeb,&MyClickWidget::clicked,this,&DIYSupportPage::on_officialWeb_clicked);

    m_pKylinOfficialWeb_1 = new KToolButton(this);
    m_pKylinOfficialWeb_1->setIcon(QIcon::fromTheme("software-properties-symbolic"));

    m_pKylinOfficialWeb_2 = new QLabel(this);
    m_pKylinOfficialWeb_2->adjustSize();//->setFixedSize(84,20);
    m_pKylinOfficialWeb_2->setText(tr("To KylinOS Official Web"));//"前往麒麟官网");
    m_pKylinOfficialWeb_2->setAlignment(Qt::AlignLeft);
    m_pKylinOfficialWeb_2->setAlignment(Qt::AlignVCenter);
    m_pKylinOfficialWeb_2->setAttribute(Qt::WA_TransparentForMouseEvents);

    m_pKylinOfficialWeb_3 = new QLabel(this);
    m_pKylinOfficialWeb_3->adjustSize();//->setFixedSize(263,17);
    m_pKylinOfficialWeb_3->setText(tr("Access the Web, find the answers of the \nnormal problems."));//"用户通过访问官网，自助寻求技术与帮助。");
    m_pKylinOfficialWeb_3->setAlignment(Qt::AlignLeft);
    m_pKylinOfficialWeb_3->setAlignment(Qt::AlignVCenter);
    m_pKylinOfficialWeb_3->setAttribute(Qt::WA_TransparentForMouseEvents);

    m_kylinManual = new MyClickWidget(this);
    m_kylinManual->setFixedSize(340,120);
    m_kylinManual->setObjectName("kylinManual");


    connect(m_kylinManual,&MyClickWidget::clicked,this,&DIYSupportPage::on_kylinManual_clicked);

    m_pKylinManual_1 = new KToolButton(this);
    m_pKylinManual_1->setIcon(QIcon::fromTheme("ukui-sold-symbolic"));

    m_pKylinManual_2 = new QLabel(this);
    m_pKylinManual_2->adjustSize();
    m_pKylinManual_2->setText(tr("Guidance"));//"帮助手册");
    m_pKylinManual_2->setAlignment(Qt::AlignLeft);
    m_pKylinManual_2->setAlignment(Qt::AlignVCenter);

    m_pKylinManual_3 = new QLabel(this);
    m_pKylinManual_3->adjustSize();//->setFixedSize(309,17);
    m_pKylinManual_3->setText(tr("Check Manuals to solve the problem."));//"查询帮助手册，寻求支持与帮助。");
    m_pKylinManual_3->setAlignment(Qt::AlignLeft);
    m_pKylinManual_3->setAlignment(Qt::AlignVCenter);

    QHBoxLayout *HmainLayout_KylinPic = new QHBoxLayout();
    HmainLayout_KylinPic->setSpacing(0);
    HmainLayout_KylinPic->setMargin(0);
    HmainLayout_KylinPic->addSpacing(30);
    HmainLayout_KylinPic->addWidget(m_pKylinPic,1);
    HmainLayout_KylinPic->addSpacing(30);
    HmainLayout_KylinPic->addStretch(99);

    QHBoxLayout *HmainLayout_MoreInfoLink = new QHBoxLayout();
    HmainLayout_MoreInfoLink->setSpacing(0);
    HmainLayout_MoreInfoLink->setMargin(0);
    HmainLayout_MoreInfoLink->addStretch();
    HmainLayout_MoreInfoLink->addWidget(m_pMoreInfoLink_1);
    HmainLayout_MoreInfoLink->addWidget(m_pMoreInfoLink_2);
    HmainLayout_MoreInfoLink->addWidget(m_pMoreInfoLink_3);
    HmainLayout_MoreInfoLink->addSpacing(30);

    QHBoxLayout *HmainLayout_PageTitle = new QHBoxLayout();
    HmainLayout_PageTitle->setSpacing(0);
    HmainLayout_PageTitle->setMargin(0);
    HmainLayout_PageTitle->addSpacing(30);
    HmainLayout_PageTitle->addWidget(m_pPageTitle,1);
    HmainLayout_PageTitle->addStretch();

    QHBoxLayout *KylinOfficialWebLayout_I = new QHBoxLayout();
    KylinOfficialWebLayout_I->setMargin(0);
    KylinOfficialWebLayout_I->setSpacing(0);
    KylinOfficialWebLayout_I->addSpacing(0);
    KylinOfficialWebLayout_I->addWidget(m_pKylinOfficialWeb_1);
    KylinOfficialWebLayout_I->addSpacing(4);
    KylinOfficialWebLayout_I->addWidget(m_pKylinOfficialWeb_2);
    KylinOfficialWebLayout_I->addStretch(99);

    QVBoxLayout *KylinOfficialWebLayout_II = new QVBoxLayout();
    KylinOfficialWebLayout_II->setMargin(20);
    KylinOfficialWebLayout_II->setSpacing(0);
    KylinOfficialWebLayout_II->addSpacing(0);
    KylinOfficialWebLayout_II->addLayout(KylinOfficialWebLayout_I);
    KylinOfficialWebLayout_II->addSpacing(4);
    KylinOfficialWebLayout_II->addWidget(m_pKylinOfficialWeb_3);
    KylinOfficialWebLayout_II->addStretch(99);

    m_officialWeb->setLayout(KylinOfficialWebLayout_II);

    QHBoxLayout *kylinManualLayout_I = new QHBoxLayout();
    kylinManualLayout_I->setMargin(0);
    kylinManualLayout_I->setSpacing(0);
    kylinManualLayout_I->addSpacing(0);
    kylinManualLayout_I->addWidget(m_pKylinManual_1,1);
    kylinManualLayout_I->addSpacing(4);
    kylinManualLayout_I->addWidget(m_pKylinManual_2,1);
    kylinManualLayout_I->addStretch(99);

    QVBoxLayout *kylinManualLayout_II = new QVBoxLayout();
    kylinManualLayout_II->setMargin(20);
    kylinManualLayout_II->setSpacing(0);
    kylinManualLayout_II->addSpacing(0);
    kylinManualLayout_II->addLayout(kylinManualLayout_I,1);
    kylinManualLayout_II->addSpacing(4);
    kylinManualLayout_II->addWidget(m_pKylinManual_3,1);
    kylinManualLayout_II->addStretch(99);

    m_kylinManual->setLayout(kylinManualLayout_II);

    QHBoxLayout *HmainLayout = new QHBoxLayout();
    HmainLayout->setSpacing(0);
    HmainLayout->setMargin(0);
    HmainLayout->addSpacing(30);
    HmainLayout->addWidget(m_officialWeb);
    HmainLayout->addSpacing(20);
    HmainLayout->addWidget(m_kylinManual);
    HmainLayout->addStretch();

    QVBoxLayout *VmainLayout = new QVBoxLayout();
    VmainLayout->setSpacing(0);
    VmainLayout->setMargin(0);
    VmainLayout->addLayout(HmainLayout_KylinPic);
    VmainLayout->addSpacing(8);
    VmainLayout->addLayout(HmainLayout_MoreInfoLink);
    VmainLayout->addSpacing(20);
    VmainLayout->addLayout(HmainLayout_PageTitle);
    VmainLayout->addSpacing(10);
    VmainLayout->addLayout(HmainLayout);
    VmainLayout->addStretch();
    this->setLayout(VmainLayout);
}
/************************************************
* 函数名称：eventFilter
* 功能描述：m_pMoreInfoLink_2点击跳转到kylin主页
* 输入参数：
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
bool DIYSupportPage::eventFilter(QObject *obj, QEvent *ev)
{
    if(obj == m_pMoreInfoLink_2)
    {
        if(ev->type() == QEvent::MouseButtonPress)
        {
            /* SDK功能点： 跳转官网主页*/
            GlobalData::SDKPointJumpOfficicalWebsite();

            QDesktopServices::openUrl(QUrl("https://www.kylinos.cn/support/problem.html"));
        }
    }

    return QWidget::eventFilter(obj,ev);
}


/************************************************
* 函数名称：on_officialWeb_clicked
* 功能描述：点击跳转到ubuntukylin主页
* 输入参数：
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void DIYSupportPage::on_officialWeb_clicked()
{
    /* SDK功能点： 跳转官网主页*/
    GlobalData::SDKPointJumpOfficicalWebsite();
    
    QDesktopServices::openUrl(QUrl("https://www.kylinos.cn/support/problem.html"));
}
/************************************************
* 函数名称：on_kylinManual_clicked
* 功能描述：点击打开用户手册
* 输入参数：
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void DIYSupportPage::on_kylinManual_clicked()
{
    if (!m_daemonIpcDbus->daemonIsNotRunning()){
        //增加标题栏帮助菜单、F1快捷键打开用户手册
        m_daemonIpcDbus->showGuide("");
    }
}

void DIYSupportPage::changeFont(QFont curFont)
{
    double smallFontSize = (static_cast<double>(curFont.pointSizeF())/14)*12;
    QFont smallFont;
    smallFont.setPointSizeF(smallFontSize);
    QFont normalFont = curFont;
    //小字
    m_pMoreInfoLink_1->setFont(smallFont);
    m_pMoreInfoLink_2->setFont(smallFont);
    m_pMoreInfoLink_3->setFont(smallFont);
    m_pPageTitle->setFont(smallFont);
    m_pKylinOfficialWeb_3->setFont(smallFont);
    m_pKylinManual_3->setFont(smallFont);

    //中等字
    m_pKylinOfficialWeb_2->setFont(normalFont);
    m_pKylinManual_2->setFont(normalFont);
}
